#include "StdAfx.h"
//-------------------------------------------------------------------------------------------------
//ImageProcSampleLib.cpp  -  Interface to ImageProcSample.dll - a simple library used by ImageCurator          
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2012 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Apr 2012
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------

#include "ImageProcSampleLib.h"
#include "DummyOne.h"
#include "DummyTwo.h"
#include "DummyThree.h"
#include "DummyAnalysis.h"

IMAGEPROCSAMPLE_API IImageProcStepLibDyn *CreateImageProcStepLib() //this function name must match ImageExptLib::CreateFunctionName 
{
	return new ImageProcSampleLib();
}

ImageProcSampleLib::ImageProcSampleLib(void) :
	_LibApi('\0')
{
	_LibApi = new ImageProcStepLibAuto();
							//todo - get this information from VS_VERSION_INFO so it is consistent with DLL file props
	_LibApi->SetLibNameVersion(GetLibName(), GetLibVersion(), GetLibInterfaceVersion());
	_LibApi->SetLibOwnerDetails("Maximodex Limited", "Copyright 2012, Will Stott", "www.maximodex.com/ProductSupport/ImageCurator/ImageProcLibs/ImageProcSample");
	_LibApi->SetLibDescription("dummy - use only for testing - it doesn't do anything");

	DummyOne *one = new DummyOne();
	if(_LibApi->AddFunction(one) == false)
			delete one;
	DummyTwo *two = new DummyTwo();
	if(_LibApi->AddFunction(two) == false)
			delete two;
	DummyThree *three = new DummyThree();
	if(_LibApi->AddFunction(three) == false)
			delete two;
	
	DummyAnalysis *analysis = new DummyAnalysis();
	if(_LibApi->AddFunction(analysis) == false)
			delete analysis;
	//.... add other functions

	_LibApi->Validate();


}


ImageProcSampleLib::~ImageProcSampleLib(void)
{
	ImageExptLib::LogMsg("ImageProcSampleLib::~ImageProcSampleLib", "entry");	
	if (_LibApi != '\0')
	{
		ImageExptLib::LogMsg("ImageProcSampleLib::~ImageProcSampleLib", "delete _LibApi");	
		delete _LibApi;
	}
	_LibApi = '\0';
	ImageExptLib::LogMsg("ImageProcSampleLib::~ImageProcSampleLib", "exit");	
}

bool ImageProcSampleLib::Run(const char *fnName, ProcParamsInputs *inputs, ProcParamsOutputs *outputs)
{
	bool rc = false;

	return rc;
}


//extern HMODULE hDLLModule;
//bool ImageProcSampleLib::Init()
//{
//	//CString modFilename; 
//	LPTSTR pModFileName = (LPTSTR)_pTempBuffer;
//	if(::GetModuleFileName(hDLLModule, pModFileName, MAX_PATH) > 0) 
//	{ 
//		DWORD dwHandle = 0; 
//		DWORD dwSize = GetFileVersionInfoSize((LPTSTR)_pTempBuffer, &dwHandle); 
//		if(dwSize > 0) 
//		{ 
//			LPBYTE lpInfo = new BYTE[dwSize]; 
//			ZeroMemory(lpInfo, dwSize); 
//			if(GetFileVersionInfo(pModFileName, 0, dwSize, lpInfo)) 
//			{ 
//				//// Use the version information block to obtain the FILEVERSION. 
//								//// This will extract language specific part of versio resources. 040904E4 is English(US) locale,  
//								//// it should match to your project 
//				//UINT valLen = MAX_PATH; 
//				//LPVOID valPtr = NULL; 
//				//if(::VerQueryValue(lpInfo,  
//				//  TEXT("\\StringFileInfo\\040904E4\\FileVersion"), 
//				//  &valPtr, 
//				//  &valLen)) 
//				//{ 
//				//  CString valStr((LPCTSTR)valPtr); 
// 
//				//  AfxMessageBox(valStr); 
//				//} 
// 
//								//// This will extract so called FIXED portion of the version info 
//				UINT valLen = MAX_PATH; 
//				LPVOID valPtr = NULL; 
//				if(::VerQueryValue(lpInfo,  
//					TEXT("\\"), 
//					&valPtr, 
//					&valLen)) 
//				{ 
//					VS_FIXEDFILEINFO* pFinfo = (VS_FIXEDFILEINFO*)valPtr; 
// 
//					// convert to text 
//					//CString valStr; 
//					//valStr.Format(_T("%d.%d.%d.%d"),  
//					//	(pFinfo->dwFileVersionMS >> 16) & 0xFFFF, 
//					//	(pFinfo->dwFileVersionMS) & 0xFFFF, 
//					//	(pFinfo->dwFileVersionLS >> 16) & 0xFFFF, 
//					//	(pFinfo->dwFileVersionLS) & 0xFFFF 
//					//	); 
// 
//					//AfxMessageBox(valStr); 
//				} 
//			} 
//			delete[] lpInfo; 
//		} 
//	}
//	return true;
//}

//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------